package ar.edu.itba.it.paw.web.validator;

import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import ar.edu.itba.it.paw.web.command.EditProductForm;

@Component
public class EditProductFormValidator implements Validator {
	
	@Override
	public boolean supports(Class<?> clazz) {
		return EditProductForm.class.equals(clazz);
	}

	@Override
	public void validate(Object target, Errors errors) {
		EditProductForm form = (EditProductForm) target;
		if(form.getProduct_name().equals("")){
			errors.rejectValue("product_name", "empty");
		}
		if(form.getDescription().equals("")){
			errors.rejectValue("description", "empty");
		}
		if(form.getCategory() == null){
			errors.rejectValue("category", "invalid");
		}
			
	}
}
